From 3bac6e0694cf03e9e44acbf28ed516928cf85f89 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Mar 2015 15:29:05 -0800 Subject: [PATCH] Correctly set up paths when packaging A synthetic "Package" is being created as part of this step but its paths were pointing at the original root, not the unpacked tarball for testing. This meant that some assumptions about the relative-ness of paths didn't quite end up working out. Closes #1382 --- src/cargo/ops/cargo_package.rs | 16 +++++++++++----- src/cargo/sources/path.rs | 13 ++++++++++++- src/cargo/util/to_semver.rs | 6 ++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 426181a1a..6bf4a931a 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -6,8 +6,7 @@ use tar::Archive; use flate2::{GzBuilder, Compression}; use flate2::read::GzDecoder; -use core::source::{Source, SourceId}; -use core::Package; +use core::{Source, SourceId, Package, PackageId}; use sources::PathSource; use util::{self, CargoResult, human, internal, ChainError, Config}; use ops; @@ -160,16 +159,23 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path) // When packages are uploaded to the registry, all path dependencies are // implicitly converted to registry-based dependencies, so we rewrite those // dependencies here. + // + // We also be sure to point all paths at `dst` instead of the previous + // location that the package was original read from. In locking the + // `SourceId` we're telling it that the corresponding `PathSource` will be + // considered updated and won't actually read any packages. let registry = try!(SourceId::for_central(config)); + let precise = Some("locked".to_string()); + let new_src = try!(SourceId::for_path(&dst)).with_precise(precise); + let new_pkgid = try!(PackageId::new(pkg.name(), pkg.version(), &new_src)); let new_summary = pkg.summary().clone().map_dependencies(|d| { if !d.source_id().is_path() { return d } d.set_source_id(registry.clone()) }); let mut new_manifest = pkg.manifest().clone(); - new_manifest.set_summary(new_summary); + new_manifest.set_summary(new_summary.override_id(new_pkgid)); new_manifest.set_target_dir(dst.join("target")); - let new_pkg = Package::new(new_manifest, &manifest_path, - pkg.package_id().source_id()); + let new_pkg = Package::new(new_manifest, &manifest_path, &new_src); // Now that we've rewritten all our path dependencies, compile it! try!(ops::compile_pkg(&new_pkg, &ops::CompileOptions { diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 11352770e..8ff39be63 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -58,8 +58,19 @@ impl<'a, 'b> PathSource<'a, 'b> { } pub fn read_packages(&self) -> CargoResult> { + if self.updated { Ok(self.packages.clone()) + } else if self.id.is_path() && self.id.precise().is_some() { + // If our source id is a path and it's listed with a precise + // version, then it means that we're not allowed to have nested + // dependencies (they've been rewritten to crates.io dependencies) + // In this case we specifically read just one package, not a list of + // packages. + let path = self.path.join("Cargo.toml"); + let (pkg, _) = try!(ops::read_package(&path, &self.id, + self.config)); + Ok(vec![pkg]) } else { ops::read_packages(&self.path, &self.id, self.config) } @@ -203,7 +214,7 @@ impl<'a, 'b> PathSource<'a, 'b> { { let mut ret = Vec::new(); for pkg in self.packages.iter().filter(|p| *p == pkg) { - let loc = pkg.manifest_path().parent().unwrap(); + let loc = pkg.root(); try!(walk(loc, &mut ret, true, &mut filter)); } return Ok(ret); diff --git a/src/cargo/util/to_semver.rs b/src/cargo/util/to_semver.rs index 9fe689b13..ad6aff16e 100644 --- a/src/cargo/util/to_semver.rs +++ b/src/cargo/util/to_semver.rs @@ -22,3 +22,9 @@ impl<'a> ToSemver for &'a String { (**self).to_semver() } } + +impl<'a> ToSemver for &'a Version { + fn to_semver(self) -> Result { + Ok(self.clone()) + } +} -- 2.30.2